home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Found / FWStream / Sources / SLMemSin.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  5.4 KB  |  192 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                SLMemSin.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFound.hpp"
  11.  
  12. #ifndef FWODEXCE_H
  13. #include "FWODExce.h"
  14. #endif
  15.  
  16. #ifndef FWPRIMEM_H
  17. #include "FWPriMem.h"
  18. #endif
  19.  
  20. #ifndef FWPRIDEB_H
  21. #include "FWPriDeb.h"
  22. #endif
  23.  
  24. #define VARIABLE_MACROS
  25. #define FW_OMemorySink_Class_Source
  26. #include "SLMemSin.xih"
  27.  
  28. #ifdef FW_BUILD_MAC
  29. #pragma segment FWStream
  30. #endif
  31.  
  32.  
  33. //----------------------------------------------------------------------------------------
  34. // FW_OMemorySinkInit
  35. //----------------------------------------------------------------------------------------
  36.  
  37. SOM_Scope void  SOMLINK FW_OMemorySink__InitFromBuffer(FW_OMemorySink *somSelf, Environment *ev,
  38.         void* buffer,
  39.         long capacity,
  40.         long length)
  41. {
  42. FW_UNUSED(ev);
  43.     FW_OMemorySinkData *somThis = FW_OMemorySinkGetData(somSelf);
  44.  
  45.     _fBuffer = (char*)buffer;
  46.     _fCapacity = capacity;
  47.     _fLength = length;
  48.     _fPosition = 0;
  49.  
  50.     FW_ASSERT(_fLength <= _fCapacity);
  51. }
  52.  
  53.  
  54. //----------------------------------------------------------------------------------------
  55. // FW_OMemorySinkRead
  56. //----------------------------------------------------------------------------------------
  57.  
  58. SOM_Scope void  SOMLINK FW_OMemorySink__Read(FW_OMemorySink *somSelf, Environment *ev,
  59.         void* destination,
  60.         long count)
  61. {
  62. FW_UNUSED(ev);
  63.     FW_OMemorySinkData *somThis = FW_OMemorySinkGetData(somSelf);
  64.  
  65.     FW_ASSERT(count >= 0);
  66.     FW_ASSERT(_fPosition + count <= _fLength);
  67.  
  68.     FW_PrimitiveCopyMemory(_fBuffer + _fPosition, destination, count);
  69.     _fPosition += count;
  70. }
  71.  
  72.  
  73. //----------------------------------------------------------------------------------------
  74. // FW_OMemorySinkGetWritableBytes
  75. //----------------------------------------------------------------------------------------
  76.  
  77. SOM_Scope long  SOMLINK FW_OMemorySink__GetWritableBytes(FW_OMemorySink *somSelf, Environment *ev)
  78. {
  79.     FW_OMemorySinkData *somThis = FW_OMemorySinkGetData(somSelf);
  80.  
  81.     return _fCapacity - somSelf->GetPosition(ev);
  82. }
  83.  
  84.  
  85. //----------------------------------------------------------------------------------------
  86. // FW_OMemorySinkWrite
  87. //----------------------------------------------------------------------------------------
  88.  
  89. SOM_Scope void  SOMLINK FW_OMemorySink__Write(FW_OMemorySink *somSelf, Environment *ev,
  90.         void* source,
  91.         long count)
  92. {
  93. FW_UNUSED(ev);
  94.     FW_OMemorySinkData *somThis = FW_OMemorySinkGetData(somSelf);
  95.  
  96.     FW_ASSERT(count >= 0);
  97.     FW_ASSERT(_fPosition + count <= _fCapacity);
  98.  
  99.     FW_PrimitiveCopyMemory(source, _fBuffer + _fPosition, count);
  100.     _fPosition += count;
  101.     if (_fLength < _fPosition)
  102.         _fLength = _fPosition;
  103. }
  104.  
  105.  
  106. //----------------------------------------------------------------------------------------
  107. // FW_OMemorySinkGetLength
  108. //----------------------------------------------------------------------------------------
  109.  
  110. SOM_Scope long  SOMLINK FW_OMemorySink__GetLength(FW_OMemorySink *somSelf, Environment *ev)
  111. {
  112. FW_UNUSED(ev);
  113.     FW_OMemorySinkData *somThis = FW_OMemorySinkGetData(somSelf);
  114.  
  115.     return _fLength;
  116. }
  117.  
  118.  
  119. //----------------------------------------------------------------------------------------
  120. // FW_OMemorySinkSetLength
  121. //----------------------------------------------------------------------------------------
  122.  
  123. SOM_Scope void  SOMLINK FW_OMemorySink__SetLength(FW_OMemorySink *somSelf, Environment *ev,
  124.         long length)
  125. {
  126. FW_UNUSED(ev);
  127.     FW_OMemorySinkData *somThis = FW_OMemorySinkGetData(somSelf);
  128.  
  129.     FW_ASSERT(length <= _fCapacity);
  130.     _fLength = length;
  131. }
  132.  
  133.  
  134. //----------------------------------------------------------------------------------------
  135. // FW_OMemorySinkGetPosition
  136. //----------------------------------------------------------------------------------------
  137.  
  138. SOM_Scope long  SOMLINK FW_OMemorySink__GetPosition(FW_OMemorySink *somSelf, Environment *ev)
  139. {
  140. FW_UNUSED(ev);
  141.     FW_OMemorySinkData *somThis = FW_OMemorySinkGetData(somSelf);
  142.  
  143.     return _fPosition;
  144. }
  145.  
  146.  
  147. //----------------------------------------------------------------------------------------
  148. // FW_OMemorySinkSetPosition
  149. //----------------------------------------------------------------------------------------
  150.  
  151. SOM_Scope void  SOMLINK FW_OMemorySink__SetPosition(FW_OMemorySink *somSelf, Environment *ev,
  152.         long position)
  153. {
  154. FW_UNUSED(ev);
  155.     FW_OMemorySinkData *somThis = FW_OMemorySinkGetData(somSelf);
  156.  
  157.     FW_ASSERT(position >= 0);
  158.     FW_ASSERT(position <= _fLength);
  159.     _fPosition = position;
  160. }
  161.  
  162.  
  163. //----------------------------------------------------------------------------------------
  164. // FW_OMemorySinksomInit
  165. //----------------------------------------------------------------------------------------
  166.  
  167. SOM_Scope void  SOMLINK FW_OMemorySink__somInit(FW_OMemorySink *somSelf)
  168. {
  169.     FW_OMemorySinkData *somThis = FW_OMemorySinkGetData(somSelf);
  170.  
  171.     FW_OMemorySink_parent_FW_ORandomAccessSink_somInit(somSelf);
  172.  
  173.     _fBuffer = 0;
  174.     _fCapacity = 0;
  175.     _fLength = 0;
  176.     _fPosition = 0;
  177. }
  178.  
  179.  
  180. //----------------------------------------------------------------------------------------
  181. // FW_OMemorySinksomUninit
  182. //----------------------------------------------------------------------------------------
  183.  
  184. SOM_Scope void  SOMLINK FW_OMemorySink__somUninit(FW_OMemorySink *somSelf)
  185. {
  186.     FW_OMemorySinkData *somThis = FW_OMemorySinkGetData(somSelf);
  187.  
  188.     FW_OMemorySink_parent_FW_ORandomAccessSink_somUninit(somSelf);
  189. }
  190.  
  191.  
  192.